package pro.softzhang.algo.lc1300;

import pro.softzhang.algo.common.TreeNode;

/**
 *
 */
public class LC1372_LongestZigzagPathInABinaryTree {
    public static void main(String[] args) {

    }

    /**
     *
     */
    static
    class Solution {
        private int max = 0;

        public int longestZigZag(TreeNode root) {
            dfs(root, 0, 0);
            return max;
        }

        private void dfs(TreeNode root, int leftMax, int rightMax) {
            max = Math.max(max, Math.max(leftMax, rightMax));
            if(root == null) return;
            if(root.left != null) dfs(root.left, rightMax + 1, 0);
            if (root.right != null) dfs(root.right, 0, leftMax + 1);
        }
    }
}
